home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
- * TEXTRA AREXX script -- Mike Haas, 1991, All Rights Reserved. *
- * Freely distributable ONLY as a component of the TEXTRA package. *
- * This banner may not be removed or altered (improvements to the *
- * actual program welcome). Please document and send to me. *
- * !!! PLACE THIS FILE IN YOUR REXX: DIRECTORY !!! *
- *******************************************************************/
-
- /* SCOOT <num> {notab}
- *
- * Converted from INDENT.TEXTRA by Ron Charlton.
- *
- * SCOOT moves lines containing any portion of a selection
- * (or the current cursor line) by <NUM> spaces. All whitespace at the
- * beginning of the line is replaced with the appropriate number of TABs
- * and BLANKs (with Tab Width as specified in "Editing Preferences"),
- * _or_ if NOTAB is specified, then only BLANKs will be used.
- *
- * If <num> is positive, the move is to the right. Negative, left.
- *
- * If <num> is not provided, then shift right by "Tab Width" as above.
- * if <num> is "-" then shift left by "Tab Width" as above.
- *
- * Moving a line to the left will terminate if a line either runs out of
- * characters or some character other than BLANK enters the first column.
- *
- * SCOOT 0 will "entab" the beginning of each line in a selection.
- *
- * Some examples:
- *
- * scoot 8 move 8 spaces to the right
- * scoot -8 move 8 spaces to the left
- * scoot 4 move 4 spaces to the right
- * scoot -4 move 4 spaces to the left
- * scoot 8 notab move 8 spaces to the right, use BLANKs only
- * scoot -8 notab move 8 spaces to the left, use BLANKs only
- * scoot 0 replace leading whitespace with equivalent TABs/BLANKS
- * scoot move line(s) Tab Width to the right
- * scoot - move line(s) Tab Width to the left
- *
- * SCOOTing an entire 997-line C source file takes about 125 seconds.
- * SCOOTTEST will check the same file in 29 seconds (Amiga 3000/25).
- *
- * NOTE: If you SCOOT by amounts other than the Tab Width from Editing
- * Preferences, TABs that are embedded in the text of a line may cause
- * the text to change length. This will not damage C code, but may
- * be less than esthically pleasing.
- */
-
- /* 00001 mdh 10-nov-92 Added ability to cancel script */
- /* 00002 mdh 20-nov-92 check version (cause of 'CheckCancel') */
-
- OPTIONS results
-
- rex = 0; result = "NOTSUPPORTED" /*00002*/
- textraversion
- parse var result maj min rex
- if (result == "NOTSUPPORTED") | (rex < 3) then do
- notify "Textra V1.13 or later required for this script."
- exit
- end
-
-
-
- tabchar = d2c(9)
-
-
- /* figure out how far to move and which direction */
-
- prefs TabWidth read
- tabwidth = result
-
- parse upper arg num ' ' notab /* get the argument(s) */
-
- if (num == "") then
- num = tabwidth /* right by tab width from prefs */
-
- else if (num == "-") then
- num = -tabwidth /* left by tab width from prefs */
-
- else if (num == "NOTAB") then
- do
- /* num is omitted and notab is specified */
- notify "Scoot: You must specify a <num> if you specify {notab}."
- exit
- end
-
-
- /* figure out what which line(s) to work on */
-
- get select position /* get the select boundary, if any */
-
- if (result == "NO SELECT") then /* is nothing selected? */
-
- do
- get cursor position /* nothing selected, get cursor pos */
- parse var result cursx ' ' cursy
- LinesSelected = 0 /* means 'just cursor' */
-
- end
-
- else
-
- do
- /* yes, there is a selection, get it's boundaries */
- parse var result startx ' ' starty ' ' endx ' ' endy
- LinesSelected = (endy - starty)
-
- /* if only the 'eol' of the previous line is selected
- (nothing on this line is actually included, i.e. x==0),
- then don't include it.
- */
- if (endx > 0) then LinesSelected = LinesSelected + 1
-
- end
-
- if (LinesSelected == 0) then
-
- do
- currline = cursy
- gotoxy 0 cursy
- call scootline
- if (num > 0) then
- gotoxy cursx+num cursy
- else
- do
- if (firstcharpos == 0) then
- gotoxy cursx cursy
- else
- gotoxy max(cursx+num,0) cursy
- end
- end
-
- else
-
- do
- currline = starty; numLeft = LinesSelected
- do while (numLeft > 0)
- do
- CheckCancel; if (result == CANCEL) then exit /*00001*/
- gotoxy 0 currline
- call scootline
- currline = currline + 1
- numLeft = numLeft - 1
- end
- end
- gotoxy 0 starty
- selectto 0 starty+LinesSelected
- end
-
- exit
-
-
- scootline:
-
- get cursor char
- if (result == "-1") then
- /* empty line */
- return
- cursorchar = result
-
- if (cursorchar == ' ' | cursorchar == tabchar) then
- do
- hopto next char
- if (result == "NOT FOUND") then
- /* at end of file */
- return
- end
-
- get cursor position
- if (result == "SELECT") then
- /* cannot (?) happen */
- return
-
- parse var result firstcharpos ' ' cursoryscoot
- if (cursoryscoot ~= currline) then
- /* nothing on currline */
- return
-
- newoffset = firstcharpos + num
- if (newoffset < 0) then
- newoffset = 0
-
- /* select leading whitespace */
- gotoxy 0 currline
- selectto firstcharpos currline
- if (num < 0) then killselect
-
-
- /* figure what to replace leading whitespace with */
- if (notab == "NOTAB") then
- do
- tabcount = 0
- spacecount = newoffset
- end
- else
- do
- tabcount = newoffset % tabwidth
- spacecount = newoffset // tabwidth
- end
-
-
- /* insert TABs/BLANKs at beginning of line */
- text '"' || copies(tabchar, tabcount) || copies(' ', spacecount) || '"'
-
- /*
- if (num < 0 & abs(num) > firstcharpos) then
- do
- notify "Scoot: Line " || currline+1 || " cannot move left far enough."
- exit
- end
- */
- return
-
- Debug: procedure
- parse arg theString
- get select position /* get the select boundary, if any */
- if (result == "NO SELECT") then /* is nothing selected? */
- do
- get cursor position /* nothing selected, get cursor pos */
- parse var result cursxdbg ' ' cursydbg
- WasSelected = 0 /* means 'just cursor' */
- end
- else
- do
- /* yes, there is a selection, get it's boundaries */
- parse var result cursxdbg ' ' cursydbg ' ' endxdbg ' ' endydbg
- WasSelected = 1
- end
- lastline
- text theString
- gotoxy cursxdbg cursydbg
- if (WasSelected == 1) then selectto endxdbg endydbg
- return
-
-
-